package com.hkw.servlet;

import com.hkw.service.IStudentService;
import com.hkw.service.impl.StudentServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 处理删除学生的Servlet
 */
@WebServlet(name = "DeleteStudentServlet",urlPatterns = "/delStudent")
public class DeleteStudentServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //从request里获取id
        String id = request.getParameter("id");
        //实例化接口服务
        IStudentService studentService = new StudentServiceImpl();
        //调用服务
        int del = studentService.del(Integer.parseInt(id));
        if(del==1){
            System.out.println("删除ok");
        }else{
            System.out.println("删除失败");
        }
        response.sendRedirect("studentlist");
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request,response);
    }
}
